<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>state</title>
  </head>
  <body>
    <div id="test">我是一段文本</div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script>
      function handleClick() {
        console.log('你点击了当前标签')
      }
    </script>

    <script type="text/babel">
      // 创建 Weather 组件
      class Weather extends React.Component {
        state = {
          isHot: true,
          wind: '微风'
        }

        changeWeather = () => {
          this.setState({
            isHot: !this.state.isHot
          })
        }

        render() {
          console.log(this)
          const { isHot, wind } = this.state
          return (
            <p id="title" onClick={this.changeWeather}>
              今天天气很{isHot ? '炎热' : '清爽'}，{wind}
            </p>
          )
        }
      }

      class Car {
        constructor(name, price) {
          this.name = name
          this.price = price
          this.wheel = 4
        }
        // 把当前属性添加到实例对象上
        a = 1
      }

      const C1 = new Car('奔驰c63', 199)
      const C2 = new Car('宝马', 123)
      console.log(C1)

      ReactDOM.render(<Weather />, document.getElementById('test'))

      // 注意：
      // 1. 在类中通过赋值语句可直接把属性放在实例对象上，进而简写代码
    </script>
  </body>
</html>
